﻿namespace Reap.AzureResource.Data.Infrastructure
{
	using Reap.AzureResource.Model.Models;
	using Reap.Common.Runtime.Dependency;

	[Dependency(typeof(IUnitOfWork),ComponentLifeStyle.InRequestScope,Key = "IUnitOfWork")]
	public class UnitOfWork : IUnitOfWork
	{
		#region Fields

		private readonly IDatabaseFactory dbFactory;

		private AzureResourceContext dbContext;

		#endregion

		#region Constructors and Destructors

		public UnitOfWork(IDatabaseFactory dbFactory)
		{
			this.dbFactory = dbFactory;
		}

		#endregion

		#region Properties

		private AzureResourceContext DbContext
		{
			get
			{
				return this.dbContext ?? this.dbFactory.Get();
			}
		}

		#endregion

		#region Public Methods and Operators

		public void SaveChanges()
		{
			this.DbContext.SaveChanges();
		}

		#endregion
	}
}